<template>
  <div class="dashboard">
    <el-row :gutter="20">
      <el-col :span="24">
        <el-card class="welcome-card">
          <template #header>
            <div class="card-header">
              <span>欢迎使用Vue3 + Element Plus</span>
              <el-button class="button" text>操作按钮</el-button>
            </div>
          </template>
          <div class="card-content">
            <h2>功能特性</h2>
            <el-row :gutter="20">
              <el-col :span="8" v-for="feature in features" :key="feature.title">
                <el-card class="feature-card" shadow="hover">
                  <div class="feature-icon">
                    <el-icon :size="40" :color="feature.color">
                      <component :is="feature.icon" />
                    </el-icon>
                  </div>
                  <h3>{{ feature.title }}</h3>
                  <p>{{ feature.description }}</p>
                </el-card>
              </el-col>
            </el-row>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" style="margin-top: 20px">
      <el-col :span="12">
        <el-card>
          <template #header>
            <span>数据统计</span>
          </template>
          <div>
            <p>用户数量: {{ stats.userCount }}</p>
            <p>订单数量: {{ stats.orderCount }}</p>
            <p>收入: ¥{{ stats.revenue }}</p>
          </div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card>
          <template #header>
            <span>快速操作</span>
          </template>
          <div class="quick-actions">
            <el-button type="primary" @click="handleCreate">创建新项目</el-button>
            <el-button type="success" @click="handleRefresh">刷新数据</el-button>
            <el-button type="warning" @click="handleSettings">系统设置</el-button>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { reactive, onMounted } from 'vue'
import { useDark, useToggle } from '@vueuse/core'
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
  User,
  Goods,
  TrendCharts
} from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

const isDark = useDark()
const toggleDark = useToggle(isDark)

const features = [
  {
    title: 'Vue 3 Composition API',
    description: '使用最新的Composition API，代码更加简洁和可维护',
    icon: Document,
    color: '#409EFF'
  },
  {
    title: 'Element Plus',
    description: '基于Vue 3的组件库，提供丰富的UI组件',
    icon: IconMenu,
    color: '#67C23A'
  },
  {
    title: 'Pinia状态管理',
    description: '轻量级状态管理库，替代Vuex',
    icon: Location,
    color: '#E6A23C'
  }
]

const stats = reactive({
  userCount: 0,
  orderCount: 0,
  revenue: 0
})

const loadStats = async () => {
  // 模拟API调用
  await new Promise(resolve => setTimeout(resolve, 1000))
  stats.userCount = Math.floor(Math.random() * 1000) + 100
  stats.orderCount = Math.floor(Math.random() * 500) + 50
  stats.revenue = Math.floor(Math.random() * 10000) + 1000
}

const handleCreate = () => {
  ElMessage.success('创建新项目功能待实现')
}

const handleRefresh = () => {
  loadStats()
  ElMessage.success('数据已刷新')
}

const handleSettings = () => {
  ElMessage.info('系统设置功能待实现')
}

onMounted(() => {
  loadStats()
})
</script>

<style scoped>
.dashboard {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.welcome-card {
  margin-bottom: 20px;
}

.feature-card {
  text-align: center;
  padding: 20px;
}

.feature-icon {
  margin-bottom: 15px;
}

.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quick-actions .el-button {
  margin: 5px 0;
}
</style>